package com.shangguigu.crud.service;

import java.util.List;
/**
 * 增删改查的业务层
 */
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.shangguigu.crud.bean.Employee;
import com.shangguigu.crud.bean.EmployeeExample;
import com.shangguigu.crud.bean.EmployeeExample.Criteria;
import com.shangguigu.crud.dao.EmployeeMapper;



@Service
public class EmployeeService {
	@Autowired
	EmployeeMapper employeeMapper;
	/**
	 * 查所有员工
	 * @return
	 */
	public List<Employee> getAll(){
		List<Employee> list = employeeMapper.selectByExampleWithdept(null);
		return  list;
		
	}
	/**
	 * 员工保存
	 * @param e
	 */
	public void saveEmp(Employee e) {
		System.out.println("保存考试");
		// TODO Auto-generated method stub
		employeeMapper.insertSelective(e);
	}
	/**
	 * 检验用户名是否可用
	 * @param empName
	 * @return
	 */
	public boolean check(String empName) {
		// TODO Auto-generated method stub
		System.out.println("开始检验service");
		EmployeeExample example =new EmployeeExample();
		Criteria createCriteria = example.createCriteria();
		createCriteria.andEmpNameEqualTo(empName);
		long count = employeeMapper.countByExample(example);
		//==0也就是true表示可用 
		return count ==0;
	}
	/**
	 * 按照员工id查询员工
	 * @param id
	 * @return
	 */
	public Employee getEmpName_update(Integer id) {
		// TODO Auto-generated method stub
		Employee selectByPrimaryKey = employeeMapper.selectByPrimaryKey(id);
		return selectByPrimaryKey;
	}
	/**
	 * 员工更新
	 * @param employee
	 */
	public void updateEmp(Employee employee) {
		// TODO Auto-generated method stub
		System.out.println("从数据库拿到了数据");
		employeeMapper.updateByPrimaryKeySelective(employee);
		System.out.println("从数据库拿到了数据"+employee);
		
	}
}
